package com.ssfGame.puremvc.view.module.gameOver.vc
{
	import api.event.CallFunName;
	
	import com.game.api.APICore;
	import com.game.baseMc.BaseMc;
	import com.game.btnClass.BtnClass_bright;
	import com.game.utils.GlobalFun;
	import com.ssfGame.puremvc.StaticConst;
	import com.ssfGame.puremvc.view.mc.GameTestBtn;
	import com.ssfGame.puremvc.view.module.ModuleVC;
	
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	
	public class GameOverVC extends ModuleVC
	{
		public static const USER_CHANGE:String="user_change"//用户离开或者加入
		public static const START_GAME:String="start_game"//重新开始游戏
		private var _clewTxt:TextField;
		private var _btnListName:Array=["再来一次","推荐PVP"];
		private var _isUseLeave:Boolean=false;
		public function GameOverVC()
		{
			StaticConst.apiCore.currClass=(this);//必须有
			APICore.getInstance().callAPIFun(CallFunName.A_SET_GAME_STATE,false);//通知API游戏结束
			init();
		}
		private function init():void{
			_clewTxt=new TextField();
			_clewTxt.text="调试信息..."
			addChild(_clewTxt);
			copyBtnList();
			isDisRecommendBtn(4);//显示推荐
		}
		public function gc():void{
			gcVC();
			isDisRecommendBtn();
		}
		private function copyBtnList():void{
			for(var i:uint=0;i<_btnListName.length;i++){
				var _btn:GameTestBtn=new  GameTestBtn();
				var _point:Point=GlobalFun.getListPoint(i,7,112,40);
				_btn.x=28+_point.x;
				_btn.y=42+_point.y;
				_btn.id=i;
				_btn.txt.text=_btnListName[i];
				this.addChild(_btn);
				_btnEventList.push(new BtnClass_bright(_btn,btnClick,null,null,true));
			}
		}
		private function btnClick(e:MouseEvent):void{
			var _btn:GameTestBtn=e.currentTarget as GameTestBtn;
			switch(_btn.id){
				case 0:
					sendAgain();
					break;
				case 1:
					recommend();
					break;
			}
		}
		//====================================
		//API调用游戏方法
		//初始化游戏公共方法
		public function  initPVP(data:*=null):void{
			gc();
			sendToMediator(USER_CHANGE);
		}
		//有用户离开或加入
		public function UseChange(isAdd:Boolean=false):void{
			if(isAdd){
				_clewTxt.text="用户加入!";
				initPVP();
			}else{
				_clewTxt.text="用户已经退出!";
				_isUseLeave=true;
			}
		}
		//对方想重来
		public function wantAgain(data:*=null):void{
			_clewTxt.text="对方想重来!";
		}
		//重新开始游戏
		public function again(data:*=null):void{
			gc();
			sendToMediator(START_GAME);
		}
		//暂停游戏
		public function  stopGame(isStop:Boolean):void{
			
			if(isStop){
				
			}else{
				
			}
			
		}
		
		//====================================
		//调用API方法
		
		
		
		//====================================
		//游戏间通信方法
		private function isDisRecommendBtn(type:uint=0):void{
			StaticConst.apiCore.callAPIFun(CallFunName.A_IS_SHOW_RECOMMENDBTN,type);
		}
		private function recommend():void{
			StaticConst.apiCore.callAPIFun(CallFunName.A_SHOW_RECOMMEND);
		}
		private function sendAgain():void{
			if(StaticConst.isRobot){
				again();
			}else if(_isUseLeave){
				initPVP();
			}else{
				StaticConst.apiCore.callAPIFun(CallFunName.A_ASK_AGAIN);
			}
		}
		
	}
}